home *** CD-ROM | disk | FTP | other *** search
- //* * * Archive created by MONTA utility * * *
-
- //<FILE="printsf.h">
- extern int vsprintf(char *__buffer, const char *__format, void *__arglist);
-
- #define __size(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int)-1))
-
- #define va_start(ap, parmN) ((void)((ap) = (void *)((char *)(&parmN)+__size(parmN))))
-
- #define va_arg(ap, type) (*(type *)(((*(char **)&(ap))+=__size(type))-(__size(type))))
- #define va_end(ap) ((void)0)
- //</FILE>
-
- //<FILE="crtwin.h">
- struct crtwin //structure type of crtwin_dta global variable
- {
- int left;
- int top;
- int right;
- int bottom;
- };
-
- extern struct crtwin crtwin_dta;
-
- #define xi crtwin_dta.left
- #define xf crtwin_dta.right
- #define yi crtwin_dta.top
- #define yf crtwin_dta.bottom
- //</FILE>
-
- //<FILE="crtvar.c">
- //Declaration and initialization of CRT.H functions global variables.
- //The comments about them refers to expected or default values, not to actual
- //values. If actual values are different of default values, the user might
- //want to load in these variables the actual values (using some special
- //functions or changing their values) in order to CRT.H functions work
- //properly
-
- int vmode_x=80; //number of expected columns in text mode (default=80)*
- int vmode_y=25; //number of expected rows in text mode (default=25)*
- int vmode_mode=3; //expected video mode (default=3) (updated by CRT.H functions)
- //* by CRT.H functions
- //They might be sometimes different from the actual number
- //of rows and columns in current text mode. To load their
- //actual values use crt_detect. crt_init also updates
- //crtwin_dta coordinates to full screen.
-
- int crt_direct=0;// if == 0 CRT.H functions write/read directly to video RAM,
- //otherwise, they write/read by BIOS calls (INT 10h)
- int crt_page=0; //text page used when crt_direct!=0
-
- int crt_EVGA_addr=0x3C0; //EGA/VGA base port address. Alternate at 0x2C0
-
- char far *video_addr=(char far*)0xb8000000UL;
- //base address for the video map (RAM)
-
- char far *crtvar_p; //pointer used in many functions to access the video RAM
-
- struct crtwin //coordinates used by crtwindow and printsj
- {
- int left;
- int top;
- int right;
- int bottom;
- }crtwin_dta={(int)-1,(int)-1,(int)80,(int)25}; //default values. This line means:
- //crtwin_dta.left=-1;
- //crtwin_dta.top=-1;
- //crtwin_dta.right=80;
- //crtwin_dta.bottom=25;
-
- int crtwin_just=1; //used by printsj and printsjc. Default=1(CENTER TEXT)
- //</FILE>
-
- //<FILE="crtdtect.c">
- unsigned char __inportb__( int __portid );
- unsigned int __inportw__( int __portid );
- void __outportb__( int __portid, unsigned char __value );
- void __outportw__( int __portid, unsigned int __value );
-
- #define inportb __inportb__
- #define outportb __outportb__
-
- #define MK_FP( seg,ofs )( (void _seg * )( seg ) +( void near * )( ofs ))
-
- #define word unsigned int
- #define byte unsigned char
-
- extern int vmode_x;
- extern int vmode_y;
- extern int vmode_mode;
- extern int crt_direct;
- extern int crt_page;
- extern int crt_EVGA_addr; //EGA/VGA base port address.
- extern char far *video_addr;
-
- void crt_detect(int mode)
- //mode values:
- //1 - CGA
- //2 - MCGA
- //3,4,5 - EGA
- //9 - VGA,SVGA or better
- {
- register word a0;
- register word a1;
- //detects number of columns
- vmode_x=*(word far *)0x40004AUL;
- //detects current video mode
- vmode_mode=*(byte far *)0x400049UL;
- //detects current video page
- crt_page=*(byte far *)0x400062UL;
-
- if ((mode>=2 && mode<=5)||mode==9) //if video is MCGA, EGA, VGA, or better
- {
- vmode_y=(*(byte far *)0x400084UL)+1; //detects vmode_y
- if (mode!=2) //if video is not MCGA.
- {
- //detects if video is in text mode or graphics mode
- inportb(crt_EVGA_addr-6u);
- inportb(crt_EVGA_addr+0x1Au); //sets video's internal flipflop to r/w ATC index register
- a0=inportb(crt_EVGA_addr+1u);
- a0&=0xc0;
- a0|=0x10;
- outportb(crt_EVGA_addr,a0); //writes ATC index register and set's video's internal
- //flipflop to r/w ATC data register
- a0=inportb(crt_EVGA_addr+1u); //reads video status register
- //a0 = EGA/VGA ATC mode control register
-
- inportb(crt_EVGA_addr-6u);
- inportb(crt_EVGA_addr+0x1Au); //sets video's internal flipflop to r/w ATC index register
- a1=inportb(crt_EVGA_addr+1u);
- a1&=0xe0;
- a1|=0x20;
- outportb(crt_EVGA_addr,a1); //writes ATC index register and set's video's internal
-
- //Bitfields for EGA/VGA ATC mode control register:
- //Bit(s) Description (Table P269)
- // 7 (VGA) SB/SG select (0=4 pages of 64 regs, 1=16 pages of 16 regs)
- // 6 (VGA) PELCLK/2 (0=4bit color, 1=8bit color)
- // 5 (VGA) enable pixel panning (0=all, 1=up to line compare register value)
- // 4 reserved
- // 3 background intensity (0=16 colors, 1=blink)
- // 2 line graphics enable (0=background, 1=line 8=9)
- // 1 1=mono, 0=color select
- // 0 1=graphics, 0=text select
- //extracted from Ralf Brown's Interrupt List (file PORTS.LST)
- crt_direct=a0%2;
- }
- else
- goto jmp1;
- }
- else //if video is not MCGA, EGA, VGA or better
- {
- vmode_y=25;
- jmp1: //if video is not EGA, VGA or better
- crt_direct=((*(byte far *)0x400065UL)&0x02)/2u;
- }
-
- //detects text buffer base address if video is in text mode
- if (!crt_direct)
- {
-
- if (vmode_mode!=7)
- a0=0xb800;
- else
- a0=0xb000;
- a1=*(word far*)0x40004EUL; //a1=current page start address in regen buffer
- video_addr=(char far*)MK_FP(a0+a1/16,a1%16);
- }
- }
- //</FILE>
-
- //<FILE="crt_init.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crtwin_just;
-
- #include "crtwin.h"
-
- extern void crt_detect(int mode);
-
- void crt_init(int mode)
- {
- crt_detect(mode);
- xi=-1;
- yi=-1;
- xf=vmode_x;
- yf=vmode_y;
- crtwin_just=1; //CENTER_TEXT
- }
- //</FILE>
-
- //<FILE="vmode.c">
- extern int vmode_x; //number of columns in text mode (default=80)
- extern int vmode_y; //number of rows in text mode (default=25)
- int vmode_lm=3; //last mode used or selected by videomode (default=25x80)
- int vmode_am=3; //current mode used by videomode (default=25x80)
-
- void videomode (int newmode) //tells the functions declared in CRT.H which is
- //the "selected" mode number of rows and columns.
- {
- if (newmode==-1)
- newmode=vmode_lm;
- vmode_lm=vmode_am;
- vmode_am=newmode;
- switch (vmode_am)
- {
- case 0: //executes the immediately following line
- case 1: vmode_y=25; vmode_x=40; break; //25 x 40
- case 2:
- case 3:
- case 7: vmode_y=25; vmode_x=80; break; //25 x 80
- case 24:vmode_y=43; vmode_x=40; break; //43 x 40 (ega)
- case 32:vmode_y=43; vmode_x=80; break; //43 x 80 (ega)
- case 48:vmode_y=50; vmode_x=40; break; //50 x 40 (vga)
- case 64:vmode_y=50; vmode_x=80; break; //50 x 80 (vga)
- }
- }
- //</FILE>
-
- //<FILE="crtmode.c">
- #define intm(intnum) asm int intnum
- extern int vmode_x;
- extern int vmode_mode;
- extern int crt_page;
-
- int getcrtmode (void) //returns the current video mode and updates
- //vmode_x and crt_page to current values.
- //vmode_y is not updated to actual value.
- {
- int a0;
- asm push ax;
- asm push bx;
- _AH=0x0F;
- intm(0x10);
- asm mov bl,ah;
- a0=_AL;
- vmode_x=_BL;
- crt_page=_BH;
- vmode_mode=a0;
- asm pop bx;
- asm pop ax;
- return a0;
- }
-
- void setcrtmode (int mode) //changes video mode and calls getcrtmode
- {
- asm push ax;
- asm xor ax,ax; //ax=0;
- _AL=mode;
- asm int 0x10;
- asm pop ax;
- getcrtmode();
- }
- //</FILE>
-
- //<FILE="crtpage.c">
- extern int vmode_mode;
- extern char far *video_addr;
-
- extern int getcrtmode (void);
-
- #define MK_FP( seg,ofs )( (void _seg * )( seg ) +( void near * )( ofs ))
-
- #define word unsigned int
-
- void setcrtpage (int page) //selects active display page
- //the actual selected page number is stored in crt_page after a call to this
- //function
- {
- register word a0,a1;
- //changes active display page
- asm push ax;
- _AL=page;
- _AH=0x05;
- asm int 0x10;
- asm pop ax;
- //updates vmode_mode and crt_page
- getcrtmode ();
- //updates video_addr;
- if (vmode_mode!=7)
- a0=0xb800;
- else
- a0=0xb000;
- a1=*(word far*)0x40004EUL; //a1=current page start address in regen buffer
- video_addr=(char far*)MK_FP(a0+a1/16,a1%16);
- }
- //</FILE>
-
- //<FILE="crt_gtxy.c">
- extern int crt_page;
-
- void crt_gotoxy (int x, int y) //changes cursor position in text page defined
- //by crt_page.
- {
- asm push ax;
- asm push bx;
- asm push dx;
- _BH=crt_page;
- _DH=y;
- _DL=x;
- _AH=0x02;
- asm int 0x10;
- asm pop dx;
- asm pop bx;
- asm pop ax;
- }
-
- //</FILE>
-
- //<FILE="getxy.c">
- extern int crt_page;
-
- int crt_getxy (int *x, int *y) //gets current cursor position in text page
- //defined by crt_page.
- {
- int rtn;
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- _BH=crt_page;
- _AH=0x03;
- asm int 0x10;
- rtn=_DX;
- *y=_DH;
- *x=_DL;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- return rtn;
- }
- //</FILE>
-
- //<FILE="getcrtch.c">
- extern int vmode_x;
- extern int crt_direct;
- extern int crt_page;
- extern char far *video_addr;
-
- extern void crt_gotoxy (int x, int y);
- extern int crt_getxy (int *x, int *y);
-
- int getcrtchar (int x, int y)
- //gets the character from position (x,y)
- {
- int xo,yo;
- char far *crtvar_p;
- unsigned int z;
-
- if (!crt_direct)
- {
- crtvar_p=video_addr + 2 * (x + y*vmode_x);
- return *crtvar_p;
- }
-
- crt_getxy (&xo,&yo);
- crt_gotoxy (x,y);
- asm push ax;
- asm push bx;
- _BH=crt_page;
- _AH=0x08;
- asm push bp;
- asm int 0x10;
- asm pop bp;
- z=_AX;
- asm pop bx;
- asm pop ax;
- crt_gotoxy(xo,yo);
- return (z%0x100);
- }
- //</FILE>
-
- //<FILE="getcrtco.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern int crt_page;
- extern char far *video_addr;
-
- extern void crt_gotoxy (int x, int y);
- extern int crt_getxy (int *x, int *y);
-
- int getcrtcolor (int x,int y)
- //gets the color from position (x,y)
- {
- int xo,yo;
- unsigned int z;
- char far *crtvar_p;
-
- if (!crt_direct)
- {
- crtvar_p=video_addr + 1 + 2 * (x + y*vmode_x);
- return *crtvar_p;
- }
-
- crt_getxy (&xo,&yo);
- crt_gotoxy (x,y);
- asm push ax;
- asm push bx;
- _BH=crt_page;
- _AH=0x08;
- asm push bp;
- asm int 0x10;
- asm pop bp;
- z=_AX;
- asm pop bx;
- asm pop ax;
- crt_gotoxy(xo,yo);
- return (z/0x100);
- }
- //</FILE>
-
- //<FILE="b_printc.c">
- extern int crt_page;
-
- extern void crt_gotoxy (int x, int y);
- extern int crt_getxy (int *x, int *y);
-
- void biosprintc (int chr, int x, int y, int color, int func)
- //prints a character at position (x,y) with color "color" if func=09h.
- //if func=0Ah prints character with no color.
- {
- int xo, yo;
- crt_getxy(&xo,&yo);
- crt_gotoxy (x,y);
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- _DH=func;
- _DL=chr;
- _BH=crt_page;
- _BL=color;
- _CX=0x01;
- asm mov ax,dx;
- asm int 0x10;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- crt_gotoxy (xo,yo);
- }
- //</FILE>
-
- //<FILE="printcn.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
- extern char far *crtvar_p;
-
- extern void biosprintc (int chr, int x, int y, int color, int func);
-
- void printcn(int c,int x, int y)
- //prints a character at position (x,y) keeping the old position color.
- {
- if ((unsigned)x>=(unsigned)vmode_x || (unsigned)y>=(unsigned)vmode_y)
- return;
- if (!crt_direct)
- {
- crtvar_p=video_addr + 2 * (x + y*vmode_x);
- *crtvar_p=(char)c;
- return;
- }
- biosprintc (c,x,y,0x07,0x0a);
- }
- //</FILE>
-
- //<FILE="printc.c">
-
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
-
- extern char far *video_addr;
- extern char far *crtvar_p;
-
- extern void biosprintc (int chr, int x, int y, int color, int func);
-
- void printc(int c, int x, int y, int color)
- //prints the character "c" with color "color" at position (x,y).
- {
- if ((unsigned)x>=(unsigned)vmode_x || (unsigned)y>=(unsigned)vmode_y)
- return;
- if (!crt_direct)
- {
- crtvar_p=video_addr + 2 * (x + y*vmode_x);
- *crtvar_p=(char)c;
- crtvar_p++;
- *crtvar_p=(char)color;
- return;
- }
- biosprintc (c,x,y,color,0x09);
- }
- //</FILE>
-
- //<FILE="changeco.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
-
- extern char far *video_addr;
-
- extern int getcrtchar (int x, int y);
- extern void printc(int c, int x, int y, int color);
-
- void changecolor(int x, int y, int color)
- //changes the color at position (x,y) replacing the old color by "color"
- {
- int chr;
- char far *crtvar_p;
- if ((unsigned)x>=(unsigned)vmode_x || (unsigned)y>=(unsigned)vmode_y)
- return;
-
- if (!crt_direct)
- {
- crtvar_p=video_addr+1 + 2 * (x + y*vmode_x);
- *crtvar_p=(char)color;
- return;
- }
- chr=getcrtchar(x,y);
- printc(chr,x,y,color);
- }
- //</FILE>
-
- //<FILE="printct.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
-
- extern char far *video_addr;
- extern char far *crtvar_p;
-
- extern int getcrtchar (int x, int y);
- extern void biosprintc (int chr, int x, int y, int color, int func);
-
- void printct(int c, int x, int y, int color, unsigned int type)
- //replaces the character and/or color of position (x,y) according
- //to type parameter.
- {
- if ((unsigned)x>=(unsigned)vmode_x || (unsigned)y>=(unsigned)vmode_y)
- return;
- if (!crt_direct)
- {
- crtvar_p=video_addr + 2 * (x + y*vmode_x);
- if (type & 0x01)
- *crtvar_p=(char)c;
- crtvar_p++;
- if (type & 0x02)
- *crtvar_p=(char)color;
- return;
- }
- if (!(type & 0x01))
- c=getcrtchar(x,y);
- if (!(type & 0x02))
- color=0x07;
- biosprintc (c,x,y,color,0x0A-(type & 0x02)/2U);
- }
- //</FILE>
-
- //<FILE="printsn.c">
- extern void printcn(int c, int x, int y);
-
- void printsn(char *s, int x, int y)
- //prints a string starting from postion (x,y), keeping the old colors of
- //positions where the string is going to be printed.
- {
- while (*s)
- {
- printcn((int)*s,x,y);
- x++;
- s++;
- }
- }
- //</FILE>
-
- //<FILE="prints.c">
- extern void printc(int c, int x, int y, int color);
-
- void prints(char *s, int x, int y, int color)
- //prints a string at position (x,y) with color "color".
- {
- while (*s)
- {
- printc((int)*s,x,y,color);
- x++;
- s++;
- }
- }
- //</FILE>
-
- //<FILE="printxy.c">
- extern void printc (int c, int x, int y, int color);
-
- void printxy (char *s, int x, int y, int dx, int dy, int color)
- //prints a string at position (x,y) with character spacing (dx,dy) with color
- {
- while (*s)
- {
- printc ((int)*s,x,y,color);
- x+=dx;
- y+=dy;
- s++;
- }
- }
- //</FILE>
-
- //<FILE="printx.c">
- extern int vmode_x;
-
- extern void printc(int c, int x, int y, int color);
-
- void printx (char *s, int x, int y, int color)
- //prints a string with special formats.
- //eg. \n \t color change, position change, pause, beep, special character,
- //and other features.
- //Note: This function doesn't changes cursor position.
- {
- int flag,color2;
- int tabsizep=8; //default tab size
- int taboffst=0; //taboffset from left border
- flag=0;
- while (*s)
- {
- if (*s>0x1b || *s<0x05)
- goto jp1;
- switch (*s) //verifies if it is a control byte (or character)
- {
- case 0x05: //prints a character with the previous defined color
- color2=color; //format => 05h;color;char;
- s++; //prints any character, even if it is a format char.
- color=*s;
- flag=1;
- s++;
- goto jp1;
- case 0x06: //changes current color format => 06h;color
- s++;
- color=*s;
- break;
- case 0x07: //sends a beep using a DOS call (INT 21h)
- asm {
- push ax
- push dx
- mov dl,0x07
- mov ah,0x02
- int 0x21
- pop dx
- pop ax
- } //format => 07h;
- break;
- case 0x08: //bkspace
- x--;
- break;
- case 0x09: //tab
- x=x-taboffst;
- x=x-(x%tabsizep)+tabsizep+taboffst;
- break;
- case 0x0a: //line feed and carriage return until column=taboffset
- y++;
- x=taboffst;
- break;
- case 0x0b: //line feed
- y++;
- break;
- case 0x0c: //goes to upper left corner
- y=0;
- x=0;
- break;
- case 0x0d: //carriage return
- x=taboffst;
- break;
- case 0x0e: //changes "x" value, which determines current column
- s++;
- x=*s;
- break;
- case 0x0f: //changes "y" value, which determines current row
- s++;
- y=*s;
- break;
- case 0x10: //changes tab size
- s++;
- tabsizep=*s;
- break;
- case 0x11: //changes taboffset
- s++;
- taboffst=*s;
- break;
- case 0x12: //increments x;
- x++;
- break;
- case 0x13: //decrements y;
- y--;
- break;
- case 0x14: //pauses until a keyboard character is available (reads a
- //single character which is ignored). Checks CTRL-BREAK
- asm push ax
- _AH=0x08;
- asm int 0x21;
- asm pop ax;
- break;
- case 0x15: //pauses until a keyboard character is available,
- //but doesn't check CRTL-BREAK.
- asm push ax;
- _AH=0x07;
- asm int 0x21;
- asm pop ax;
- break;
- case 0x1b: //prints any ascii character, even if it is a format byte
- s++;
- default: //if it isn't any format character, prints character at
- //screen
- jp1:
- while (x>=vmode_x) //protection
- {
- x=x-vmode_x;
- y++;
- }
- while (x<0) //protection
- {
- x=x+vmode_x;
- y--;
- }
- printc(*s,x,y,color);//character output at screen
- x++;
- if (flag)
- {
- color=color2;
- flag=0;
- }
- }
- s++;
- }
- }
- //</FILE>
-
- //<FILE="printt.c">
- #include "crtwin.h"
-
- extern void printc(int c, int x, int y, int color);
-
- int printtext (char *s, int x, int y, int color)
- //prints a string inside a text window defined by crtwin_dta, continuing into
- //the next line if necessary
- {
- unsigned cnt=0;
- unsigned c0, c1;
- if (x<0 || y<0)
- return 0;
- c1=xi+x+1;
- for (c0=yi+1+y;(unsigned)c0<(unsigned)yf;c0++)
- {
- while (c1<(unsigned)xf)
- {
- if (!(*s))
- return cnt;
- cnt++;
- printc(*s,c1,c0,color);
- s++;
- c1++;
- }
- c1=xi+1;
- }
- return cnt;
- }
- //</FILE>
-
- //<FILE="printsj.c">
- #include "crtwin.h"
-
- extern int crtwin_just; //default=1 (CENTER TEXT)
-
- extern void printc (int c, int x, int y, int color);
- extern unsigned int strlen(const char *__s);
-
- int __abs__(int);
-
- void printsj (char *s, int y, int color)
- //Writes a string inside the box defined by crtwin_dta struct with justification
- //defined by crtwin_just.
- {
- int a0,a1; //auxiliar variables
-
- if ((yi+1)>=yf) //protection
- return;
-
- //determines the row where the text will be written
- y=(unsigned)y%(yf-yi-1)+yi+1;
-
- //determines the position where the text will be written on screen
- //according to crtwin_dta and crtwin_just and its size
- a0=strlen(s);
- switch (crtwin_just)
- {
- case 0: a1=xi+1; break;
- case 1: a1=(xi+xf-a0+1)/2; break;
- case 2: a1=xf-a0; break;
- default: return;
- }
-
- //writes the text
- while(*s)
- {
- if ((a1>xi)&&(a1<xf)) //is char inside the box defined by crtwin_dta?
- printc(*s,a1,y,color); //if so, writes it.
- a1++;
- s++;
- }
- }
- //</FILE>
-
- //<FILE="printsjc.c">
- #include "crtwin.h"
-
- extern int crtwin_just; //default=1 (CENTER TEXT)
-
- extern void printc (int c, int x, int y, int color);
-
- int printsjc_textlen (char *s)
- //returns the size of the text excluding color "instruction" bytes.
- {
- int c0=0; //counts the number of chars to be written
- while (*s)
- {
- if (*s==6 || *s==5 || *s==0x1b)
- {
- if (*s==0x1b)
- c0++;
- s++;
- }
- else
- c0++;
- s++;
- }
- return c0;
- }
-
- void printsjc (char *s, int y, int color)
- //Writes a string inside the box defined by crtwin_dta struct with justification
- //defined by crtwin_just. Allows the user to change the color in the middle
- //of the string, inserting special characters inside the string
- {
- int a0,a1; //auxiliar variables
- int color2; //stores the old color
- int rstcolor=0; //if ==1 restores old color
-
- if ((yi+1)>=yf) //protection
- return;
-
- //determines the row where the text will be written
- y=(unsigned)y%(yf-yi-1)+yi+1;
-
- //determines the position where the text will be written on screen
- //according to crtwin_dta and crtwin_just
- a0=printsjc_textlen(s);
- switch (crtwin_just)
- {
- case 0: a1=xi+1; break;
- case 1: a1=(xi+xf-a0+1)/2; break;
- case 2: a1=xf-a0; break;
- default: return;
- }
-
- //writes the text
- while(*s)
- {
- if (*s==5)
- {
- if (!rstcolor)
- {
- color2=color;
- s++;
- color=*s;
- rstcolor++;
- }
- else
- s++;
- }
- else if (*s==6)
- {
- rstcolor=0;
- s++;
- color=*s;
- }
- else
- {
- if (*s==0x1b)
- s++;
- if ((a1>xi)&&(a1<xf)) //is char inside the box defined by crtwin_dta?
- printc(*s,a1,y,color); //if so, writes it.
- a1++;
- if (rstcolor) //restores old color
- {
- rstcolor=0;
- color=color2;
- }
- }
- s++;
- }
- }
- //</FILE>
-
- //<FILE="printsnf.c">
- extern void printsn(char *s, int x, int y);
- #include "printsf.h"
-
- int printsnf(int x, int y, char *fmt,... )
- //sends formatted output using printsn function.
- {
- void *argptr;
- char s[256];
- int rtn;
- va_start(argptr, fmt);
- rtn = vsprintf(s, fmt, argptr);
- printsn(s,x,y);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="printsf.c">
- extern void prints(char *s, int x, int y, int color);
- #include "printsf.h"
-
- int printsf(int x, int y, int color, char *fmt,... )
- //sends formatted output using prints function.
- {
- void *argptr;
- char s[256];
- int rtn;
- va_start(argptr, fmt );
- rtn = vsprintf(s, fmt, argptr);
- prints(s,x,y,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="printxyf.c">
- extern void printxy (char *s, int x, int y, int dx, int dy, int color);
- #include "printsf.h"
-
- int printxyf (int x, int y, int dx, int dy, int color, char *fmt,... )
- //sends formatted output using printxy function.
- {
- void *argptr;
- char s[256];
- int rtn;
- va_start(argptr, fmt );
- rtn = vsprintf(s, fmt, argptr);
- printxy(s,x,y,dx,dy,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="printxf.c">
- extern void printx (char *s, int x, int y, int color);
- #include "printsf.h"
-
- int printxf(int x, int y, int color, char *fmt,... )
- //sends formatted output using printx function.
- {
- void *argptr;
- char s[4096];
- int rtn;
- va_start(argptr, fmt );
- rtn = vsprintf(s, fmt, argptr);
- printx(s,x,y,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="printtf.c">
- extern int printtext (char *s, int x, int y, int color);
- #include "printsf.h"
-
- int printtextf(int x, int y, int color, char *fmt,... )
- //sends formatted output using printtext function.
- {
- void *argptr;
- char s[4096];
- int rtn;
- va_start(argptr, fmt );
- rtn = vsprintf(s, fmt, argptr);
- printtext(s,x,y,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="printsjf.c">
- extern void printsj (char *s, int y, int color);
- #include "printsf.h"
-
- int printsjf(int y, int color, char *fmt,... )
- //sends formatted output using printsj function.
- {
- void *argptr;
- char s[256];
- int rtn;
- va_start(argptr, fmt);
- rtn = vsprintf(s, fmt, argptr);
- printsj(s,y,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="prntsjcf.c">
- extern void printsjc (char *s, int y, int color);
- #include "printsf.h"
-
- int printsjcf(int y, int color, char *fmt,... )
- //sends formatted output using printsjc function.
- {
- void *argptr;
- char s[256];
- int rtn;
- va_start(argptr, fmt);
- rtn = vsprintf(s, fmt, argptr);
- printsjc (s,y,color);
- va_end(argptr);
- return rtn;
- }
- //</FILE>
-
- //<FILE="fillscr.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
-
- extern void biosprintc (int chr, int x, int y, int color, int func);
-
- void fillscr (int c, int color)
- //fills the screen with character "c" and color "color"
- {
- int c0,c1,a0;
- char far *crtvar_p;
- a0=vmode_x*vmode_y; //number of character positions in screen
- crtvar_p=video_addr;
- if (!crt_direct)
- {
- for (c0=0;c0<a0;c0++)
- {
- *crtvar_p=(char)c;
- crtvar_p++;
- *crtvar_p=(char)color;
- crtvar_p++;
- }
- return;
- }
- for (c0=0;c0<vmode_y;c0++)
- for (c1=0;c1<vmode_x;c1++)
- biosprintc (c,c1,c0,color,0x09);
- }
- //</FILE>
-
- //<FILE="barcolor.c">
- extern int vmode_x;
- extern int vmode_y;
-
- extern void changecolor(int x, int y, int color);
-
- void barcolor (int xi, int yi, int xf, int yf, int color)
- //replaces the window color. The window corners are (xi,yi) and (xf,yf)
- {
- int x,y;
-
- //Avoids waste of time in unuseless calls to chagecolor
- if (yi<0)
- yi=0;
- if (xi<0)
- xi=0;
- if (yf>=vmode_y)
- yf=vmode_y-1;
- if (xf>=vmode_x)
- xf=vmode_x-1;
-
- //Replaces the window color.
- for (y=yi;y<(yf+1);y++) //y<(yf+1) => protection against infinite loop
- for (x=xi;x<(xf+1);x++) //when yf=7FFFh. The same for x and xf
- changecolor (x,y,color);
-
- }
-
- //</FILE>
-
- //<FILE="fillbar.c">
- extern int vmode_x;
- extern int vmode_y;
-
- extern void printc(int c, int x, int y, int color);
-
- void fillbar (int c, int xi, int yi, int xf, int yf, int color)
- //fills a text-window from (xi,yi) to (xf,yf) with character "c" and color
- //"color", where (xi,yi) is the upper left corner and (xf,yf) is the lower
- //right corner of the window.
- {
- int x,y;
-
- //Avoids waste of time in unuseless calls to chagecolor
- if (yi<0)
- yi=0;
- if (xi<0)
- xi=0;
- if (yf>=vmode_y)
- yf=vmode_y-1;
- if (xf>=vmode_x)
- xf=vmode_x-1;
-
- //Replaces the window color.
- for (y=yi;y<(yf+1);y++) //y<(yf+1) => protection against infinite loop
- for (x=xi;x<(xf+1);x++) //when yf=7FFFh. The same for x and xf
- printc (c,x,y,color);
-
- }
- //</FILE>
-
- //<FILE="fillbarw.c">
- extern void fillbar (int c, int xi, int yi, int xf, int yf, int color);
-
- #include "crtwin.h"
-
- void fillbarw (int c, int color)
- {
- fillbar (c,xi+1,yi+1,xf-1,yf-1,color);
- }
- //</FILE>
-
- //<FILE="fillbox.c">
- extern int vmode_x;
- extern int vmode_y;
-
- extern void printct(int c, int x, int y, int color, unsigned int type);
-
- void fillbox (int c, int xi, int yi, int xf, int yf, int color, int func)
- //fills a text-window from (xi,yi) to (xf,yf) with character "c" and color
- //"color", where (xi,yi) is the upper left corner and (xf,yf) is the lower
- //right corner of the window.
- {
- int x,y;
- //Avoids waste of time in unuseless calls to chagecolor
- if (yi<0)
- yi=0;
- if (xi<0)
- xi=0;
- if (yf>=vmode_y)
- yf=vmode_y-1;
- if (xf>=vmode_x)
- xf=vmode_x-1;
-
- //Replaces the window color.
- for (y=yi;y<(yf+1);y++) //y<(yf+1) => protection against infinite loop
- for (x=xi;x<(xf+1);x++) //when yf=7FFFh. The same for x and xf
- printct (c,x,y,color,func);
- }
- //</FILE>
-
- //<FILE="fillboxw.c">
- extern void fillbox (int c, int xi, int yi, int xf, int yf, int color, int func);
-
- #include "crtwin.h"
-
- void fillboxw (int c, int color, int func)
- {
- fillbox (c, xi+1, yi+1, xf-1, yf-1, color, func);
- }
-
- //</FILE>
-
- //<FILE="crtframe.c">
- char crtframe_mat[]="┌─┐│┘─└│╔═╗║╝═╚║▐▀▌▌▌▄▐▐████████";
- //these characters are used to build frames with crtframe
- extern void printc(int c, int x, int y, int color);
-
- void crtframe (int xi, int yi, int xf, int yf, int color, unsigned int type)
- //creates a text frame from (xi,yi) to (xf,yf) with color and type, where
- //(xi,yi) is the upper left corner and (xf,yf) is the lower right corner.
- {
- int x,y,a0,a1;
- if (type>=0x100) //selects character obtained by (type%256) as
- { //frame character
- a0=type%0x100;
- for (a1=24;a1<32;a1++)
- crtframe_mat[a1]=a0;
- type=3;
- }
- if (type>3) //if (type>3) and (type<100h) return => these values are
- return; //reserved for future versions
- //if type==3 crtframe draws a frame with the last frame
- //character selected when (type>=100h) (default='█')
- //draws horizontal borders
- type*=8;
- a0=crtframe_mat[type+1];
- a1=crtframe_mat[type+5];
- for (x=xi+1;x<xf;x++)
- {
- printc (a0,x,yi,color);
- printc (a1,x,yf,color);
- }
- //draws vertical borders
- a0=crtframe_mat[type+3];
- a1=crtframe_mat[type+7];
- for (y=yi+1;y<yf;y++)
- {
- printc (a1,xi,y,color);
- printc (a0,xf,y,color);
- }
- //draws the corners
- printc (crtframe_mat[type ],xi,yi,color);
- printc (crtframe_mat[type+2],xf,yi,color);
- printc (crtframe_mat[type+6],xi,yf,color);
- printc (crtframe_mat[type+4],xf,yf,color);
- }
- //</FILE>
-
- //<FILE="crtframw.c">
- extern void crtframe (int xi, int yi, int xf, int yf, int color, unsigned int type);
-
- #include "crtwin.h"
-
- void crtframew(int color, unsigned int type)
- {
- crtframe(xi,yi,xf,yf,color,type);
- }
-
- //</FILE>
-
- //<FILE="mkline.c">
- extern int getcrtchar (int x, int y);
- extern void printc (int c, int x, int y, int color);
-
- char const mkline_mat[]="\
- \xff\xff\xff─\xff\xff\xff═\
- \xff┌┐┬\xff╒╕╤\
- \xff└┘┴\xff╘╛╧\
- │├┤┼│╞╡╪\
- \xff\xff\xff─\xff\xff\xff═\
- \xff╓╖╥\xff╔╗╦\
- \xff╙╜╨\xff╚╝╩\
- ║╟╢╫║╠╣╬\
- ";
- //these characters are used in automatic frame lines intersection replacement
- //algorithm by mkline_aux and mkline.
-
- void mkline_aux (int cnt, int var, unsigned int mode, int pos, int color)
- //auxiliary function for mkline.
- {
- unsigned int c0;
- unsigned int x,y;
- char mult;
- unsigned char c;
- if ((mode&0x01)==0)
- {
- x=var;
- y=cnt;
- mult=0x01;
- }
- else
- {
- x=cnt;
- y=var;
- mult=0x08;
- }
- c=getcrtchar(x,y);
- for (c0=0;c0<0x40 && c!=mkline_mat[c0];c0++);
- if(c0==0x40)
- c0=0;
- if (c0==0)
- pos=3;
- c0=(c0|(pos*mult));
- if((mode&0x02)==0)
- c0=(c0&(-4*mult-1));
- else
- c0=(c0|(4*mult));
- printc(mkline_mat[c0],x,y,color);
- }
-
- void mkline (int cnt, int bgn, int end, int color, unsigned int mode)
- //draws lines in menu boxs (text frames) with automatic character replacement
- //when another frame character is found at position where is going to be
- //printed the line.
- {
- unsigned c0;
- mkline_aux(cnt,bgn,mode,1,color);
- bgn++;
- for (c0=bgn;c0<end;c0++)
- mkline_aux(cnt,c0,mode,3,color);
- mkline_aux(cnt,end,mode,2,color);
- }
- //</FILE>
-
- //<FILE="crtwin.c">
- #include <_null.h>
-
- #include "crtwin.h"
-
- struct crtwin_inp
- {
- char *title; //Title (if title==NULL doesn't print title)
- int tcolor; //Title color
- int fchr; //character used to fill window internal area
- int fcolor; //internal window area color
- int bcolor; //border color
- int btype; //border type, same as crtframe
- };
-
- extern unsigned int strlen(const char *__s);
- extern void crtframew(int color, unsigned int type);
- extern void fillbarw (int c, int color);
- extern void printc (int c, int x, int y, int color);
- extern void prints (char *s, int x, int y, int color);
- extern void mkline_aux (int cnt, int var, unsigned int mode, int pos, int color);
-
- void crtwindow (struct crtwin_inp p0)
- {
- unsigned int a0,a2,a3;
-
- crtframew(p0.bcolor,p0.btype);
- fillbarw(p0.fchr,p0.fcolor);
- if (p0.title!=NULL)
- {
- a0=strlen(p0.title);
- a2=(xi+xf-a0)/2;
- a3=(xi+xf+a0)/2+1;
- printc(' ',a2,yi,p0.tcolor);
- printc(' ',a3,yi,p0.tcolor);
- if ((unsigned)p0.btype <2)
- {
- mkline_aux(a2,yi,1,3,p0.bcolor);
- mkline_aux(a3,yi,1,3,p0.bcolor);
- mkline_aux(yi,a2,2*p0.btype,2,p0.bcolor);
- mkline_aux(yi,a3,2*p0.btype,1,p0.bcolor);
- }
- prints(p0.title,a2+1,yi,p0.tcolor);
- }
- }
- //</FILE>
-
- //<FILE="savvideo.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
-
- extern int getcrtchar (int x, int y);
- extern int getcrtcolor (int x,int y);
-
- char far *savevideo (char far *s) //saves video contents into "s" buffer
- {
- int c0,c1,a0;
- char far *crtvar_p; //used to access the video RAM
-
- if (!crt_direct)
- {
- a0=vmode_x*vmode_y;
- crtvar_p=video_addr; //points to video RAM
- for (c0=0;c0<a0;c0++)
- {
- *s=*crtvar_p;
- *(s+1)=*(crtvar_p+1);
- crtvar_p+=2; s+=2;
- }
- }
- else
- for (c0=0;c0<vmode_y;c0++)
- for (c1=0;c1<vmode_x;c1++)
- {
- *s=getcrtchar(c1,c0); s++;
- *s=getcrtcolor(c1,c0); s++;
- }
- return s;
- }
- //</FILE>
-
- //<FILE="rstvideo.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
-
- extern void biosprintc (int chr, int x, int y, int color, int func);
-
- char far *restorevideo (char far *s) //sends "s" buffer contents to screen
- {
- int c0,c1,a0,chr;
- char far *crtvar_p; //used to access the video RAM
-
- if (!crt_direct)
- {
- a0=vmode_x*vmode_y;
- crtvar_p=video_addr; //points to video RAM
- for (c0=0;c0<a0;c0++)
- {
- *crtvar_p=*s;
- *(crtvar_p+1)=*(s+1);
- crtvar_p+=2; s+=2;
- }
- }
- else
- for (c0=0;c0<vmode_y;c0++)
- for (c1=0;c1<vmode_x;c1++)
- {
- chr=*s; s++;
- biosprintc(chr,c1,c0,*s,0x09);
- s++;
- }
- return s;
- }
- //</FILE>
-
- //<FILE="savevidw.c">
- extern int getcrtchar (int x, int y);
- extern int getcrtcolor (int x,int y);
-
- char far *savevideowin(char far *s, int xi, int yi, int xf, int yf)
- //saves a text window into "s" buffer.
- {
- int c0,c1;
- yf++; xf++;
- for (c0=yi;c0<yf;c0++)
- for (c1=xi;c1<xf;c1++)
- {
- *s=getcrtchar(c1,c0); s++;
- *s=getcrtcolor(c1,c0); s++;
- }
- return s;
- }
- //</FILE>
-
- //<FILE="rstvidw.c">
- extern void printc (int c, int x, int y, int color);
-
- char far *restorevideowin(char far *s, int xi, int yi, int xf, int yf)
- //sends "s" buffer contents to a text window.
- {
- int c0,c1,a0;
- yf++; xf++;
- for (c0=yi;c0<yf;c0++)
- for (c1=xi;c1<xf;c1++)
- {
- a0=*s;
- s++;
- printc(a0,c1,c0,*s);
- s++;
- }
- return s;
- }
- //</FILE>
-
- //<FILE="savvidw2.c">
- extern char far *savevideowin(char far *s, int xi, int yi, int xf, int yf);
-
- #include "crtwin.h"
-
- char far *savevideow(char far *s)
- {
- return (char far*) savevideowin(s,xi,yi,xf,yf);
- }
-
- //</FILE>
-
- //<FILE="rstvidw2.c">
- extern char far *restorevideowin(char far *s, int xi, int yi, int xf, int yf);
-
- #include "crtwin.h"
-
- char far *restorevideow(char far *s)
- {
- return (char far*) restorevideowin(s,xi,yi,xf,yf);
- }
-
- //</FILE>
-
- //<FILE="savecrt.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
-
- extern int getcrtchar (int x, int y);
- extern int getcrtcolor (int x,int y);
-
- #include <_NULL.H>
-
- char far *savecrt (char far *s, int mode)
- //saves screen contents into "s" buffer with mode
- {
- int c0,c1,a0;
- char far *crtvar_p; //used to access the video RAM
-
- if ((unsigned)mode>=4)
- return NULL;
-
- if (!crt_direct)
- {
- a0=vmode_x*vmode_y;
- crtvar_p=video_addr; //points to video RAM
- if (mode==0)
- {
- for (c0=0;c0<a0;c0++)
- {
- *s=*crtvar_p;
- *(s+1)=*(crtvar_p+1);
- crtvar_p+=2; s+=2;
- }
- }
- else if (mode==1)
- {
- for (c0=0;c0<a0;c0++)
- {
- *s=*(crtvar_p+1); s++;
- *s=*crtvar_p; s++;
- crtvar_p+=2;
- }
- }
- else
- {
- if (mode==3)
- crtvar_p++;
- for (c0=0;c0<a0;c0++)
- {
- *s=*crtvar_p;
- crtvar_p+=2; s++;
- }
- }
- }
- else
- {
- for (c0=0;c0<vmode_y;c0++)
- for (c1=0;c1<vmode_x;c1++)
- {
- if (mode==1)
- {
- *s=getcrtcolor(c1,c0); s++;
- *s=getcrtchar (c1,c0); s++;
- }
- else
- {
- if (mode!=3)
- {
- *s=getcrtchar(c1,c0);
- s++;
- }
- if (mode!=2)
- {
- *s=getcrtcolor(c1,c0);
- s++;
- }
- }
- }
- }
- return s;
- }
- //</FILE>
-
- //<FILE="rstcrt.c">
- extern int vmode_x;
- extern int vmode_y;
- extern int crt_direct;
- extern char far *video_addr;
-
- extern void printc (int chr, int x, int y, int color);
- extern void printcn (int c,int x, int y);
- extern void changecolor (int x, int y, int color);
-
- #include <_NULL.H>
-
- char far *restorecrt (char far *s, int mode)
- //sends "s" buffer contents to screen with mode
- {
- int c0,c1,a0,chr,color;
- char far *crtvar_p;//used to access the video RAM
-
- if ((unsigned)mode>=4)
- return NULL;
-
- if (!crt_direct)
- {
- a0=vmode_x*vmode_y;
- crtvar_p=video_addr; //points to video RAM
- if (mode==0)
- {
- for (c0=0;c0<a0;c0++)
- {
- *crtvar_p=*s;
- *(crtvar_p+1)=*(s+1);
- crtvar_p+=2; s+=2;
- }
- }
- else if (mode==1)
- {
- for (c0=0;c0<a0;c0++)
- {
- *(crtvar_p+1)=*s; s++;
- *crtvar_p=*s; s++;
- crtvar_p+=2;
- }
- }
- else
- {
- if (mode==3)
- crtvar_p++;
- for (c0=0;c0<a0;c0++)
- {
- *crtvar_p=*s;
- crtvar_p+=2; s++;
- }
- }
- }
- else
- {
- for (c0=0;c0<vmode_y;c0++)
- for (c1=0;c1<vmode_x;c1++)
- {
- if (mode<2)
- {
- if (mode==0)
- {
- chr=*s; s++;
- color=*s; s++;
- }
- else
- {
- color=*s; s++;
- chr=*s; s++;
- }
- printc(chr,c1,c0,color);
- }
- else
- {
- if (mode==2)
- {
- printcn(*s,c1,c0);
- s++;
- }
- if (mode==3)
- {
- changecolor(c1,c0,*s);
- s++;
- }
- }
- }
- }
- return s;
- }
- //</FILE>
-
- //<FILE="savecrtw.c">
- extern int getcrtchar (int x, int y);
- extern int getcrtcolor (int x,int y);
-
- #include <_NULL.H>
-
- char far *savecrtwin (char far *s, int xi, int yi, int xf, int yf, int mode)
- //saves a text window into "s" buffer with mode.
- {
- int c0,c1;
-
- if ((unsigned)mode>=4)
- return NULL;
-
- yf++; xf++;
- for (c0=yi;c0<yf;c0++)
- for (c1=xi;c1<xf;c1++)
- {
- if (mode==1)
- {
- *s=getcrtcolor(c1,c0); s++;
- *s=getcrtchar (c1,c0); s++;
- }
- else
- {
- if (mode!=3)
- {
- *s=getcrtchar(c1,c0);
- s++;
- }
- if (mode!=2)
- {
- *s=getcrtcolor(c1,c0);
- s++;
- }
- }
- }
- return s;
- }
- //</FILE>
-
- //<FILE="rstcrtw.c">
- extern void printc (int c, int x, int y, int color);
- extern void printcn (int c,int x, int y);
- extern void changecolor (int x, int y, int color);
-
- #include <_NULL.H>
-
- char far *restorecrtwin (char far *s, int xi, int yi, int xf, int yf, int mode)
- //sends "s" buffer contents to a text window with mode.
- {
- int c0,c1,chr,color;
-
- if ((unsigned)mode>=4)
- return NULL;
-
- xf++; yf++;
- for (c0=yi;c0<yf;c0++)
- for (c1=xi;c1<xf;c1++)
- {
- if (mode<2)
- {
- if (mode==0)
- {
- chr=*s; s++;
- color=*s; s++;
- }
- else
- {
- color=*s; s++;
- chr=*s; s++;
- }
- printc(chr,c1,c0,color);
- }
- else
- {
- if (mode==2)
- {
- printcn(*s,c1,c0);
- s++;
- }
- if (mode==3)
- {
- changecolor(c1,c0,*s);
- s++;
- }
- }
- }
- return s;
- }
- //</FILE>
-
- //<FILE="savcrtw2.c">
- extern char far *savecrtwin (char far *s, int xi, int yi, int xf, int yf, int mode);
-
- #include "crtwin.h"
-
- char far *savecrtw(char far *s, int mode)
- {
- return (char far*) savecrtwin(s,xi,yi,xf,yf,mode);
- }
-
- //</FILE>
-
- //<FILE="rstcrtw2.c">
- extern char far *restorecrtwin (char far *s, int xi, int yi, int xf, int yf, int mode);
-
- #include "crtwin.h"
-
- char far *restorecrtw(char far *s, int mode)
- {
- return (char far *) restorecrtwin(s,xi,yi,xf,yf,mode);
- }
- //</FILE>
-
- //<FILE="cursorsh.c">
- #define intm(intnum) asm int intnum
-
- extern int crt_page;
- extern int vmode_mode;
-
- //These functions works at text page defined by crt_page (default=0)
- void setcursorsh (unsigned int shape) //changes the cursor shape.
- //bit 15-> must be 0; bits 14,13 -> cursor blink (invisible, blinking)
- //bits 12-8 -> upper scan line bits 4-0 -> lower scan line
- //Data from Ralf Brown Files
- {
- asm push ax;
- asm push cx;
- asm push dx;
- _DH=0x01;
- _DL=vmode_mode;
- _CX=shape;
- asm mov ax,dx;
- intm(0x10);
- asm pop dx;
- asm pop cx;
- asm pop ax;
- }
-
- int getcursorsh (void) //gets the current cursor shape.
- {
- unsigned int rtn;
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- _BH=crt_page;
- _AH=0x03;
- intm(0x10);
- rtn=_CX;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- return rtn;
- }
- //</FILE>
-
- //<FILE="crtpal.c">
- #define intm(intnum) asm int intnum
-
- int getpalreg (int regpal) //returns the palette register (regpal) value
- //(DAC register number)
- //Compatibility: EGA(with UltraVision v2+), VGA, UltraVision v2+, and above
-
- {
- int a0;
- asm push ax;
- asm push bx;
- _BL=regpal;
- _BH=0xFF;
- _AX=0x1007;
- intm (0x10);
- a0=_BH;
- asm pop bx;
- asm pop ax;
- return a0; //returns selected DAC register index
- }
-
- void setpalreg (int regpal, int val) //selects DAC register for specified
- //color (palette register)
- //Compatibility: PCjr,Tandy,EGA,MCGA,VGA and above
- {
- asm push ax;
- asm push bx;
- _BH=val;
- _BL=regpal;
- _AX=0x1000;
- intm (0x10);
- asm pop bx;
- asm pop ax;
- }
-
- //</FILE>
-
- //<FILE="crtbord.c">
- #define intm(intnum) asm int intnum
-
- int getbordercolor (void) //returns the DAC register index for overscan color
- //(screen border color)
- {
- int a0;
- asm push ax;
- asm push bx;
- _BH=0xFF;
- _AX=0x1008;
- intm (0x10);
- a0=_BH;
- asm pop bx;
- asm pop ax;
- return a0;
- }
-
- void setbordercolor (int val) //set's screen border color (overscan color)
- {
- asm push ax;
- asm push bx;
- _BH=val;
- _AX=0x1001;
- intm (0x10);
- asm pop bx;
- asm pop ax;
- }
-
- //</FILE>
-
- //<FILE="crtdacr.c">
- void getdacreg (int dacreg, char *red, char *green, char *blue)
- //gets the color from individual DAC register
- {
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- _BL=dacreg;
- _AX=0x1015;
- asm int 0x10;
- *red=_DH;
- *green=_CH;
- *blue=_CL;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- }
-
- void setdacreg (int dacreg, char red, char green, char blue)
- //changes the color of a individual DAC register
- {
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- _BX=dacreg;
- _CH=green;
- _CL=blue;
- _DH=red;
- _AX=0x1010;
- asm int 0x10;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- }
-
- void setdacpgmode (int pgmode) //selects video DAC paging mode
- //pgmode== 0 => 4 Blocks of 64
- //pgmode== 1 => 16 Blocks of 16
- //this function is not valid in mode 13h (19)d
- {
- asm {
- push ax;
- push bx;
- }
- _BH=pgmode;
- asm {
- xor bl,bl; //_BL=0
- mov ax,0x1013;
- int 0x10;
- pop bx;
- pop ax;
- }
- }
-
- void setdacpage(int page) //selects video DAC color page
- //page == page number (0-3) or (0-15)
- //this function is not valid in mode 13h (19)d
- {
- asm {
- push ax;
- push bx;
- }
- _BH=page;
- asm {
- mov bl,1;
- mov ax,0x1013;
- int 0x10;
- pop bx;
- pop ax;
- }
- }
-
- int getdacpgstate (void) //returns a word containing video DAC information
- //bits 15-8 => current DAC page
- //bits 7-0 => paging mode (0 => 4 pages of 64) (1 => 16 pages of 16)
- {
- asm {
- push bx;
- mov ax,0x101A;
- int 0x10;
- }
- asm mov ax,bx;
- asm pop bx;
- return _AX;
- }
- //</FILE>
-
- //<FILE="boxwidth.c">
- unsigned char __inportb__( int __portid );
- unsigned int __inportw__( int __portid );
- void __outportb__( int __portid, unsigned char __value );
- void __outportw__( int __portid, unsigned int __value );
-
- #define inportb __inportb__
- #define outportb __outportb__
-
- extern int crt_EVGA_addr; //EGA/VGA base port address.
-
- void setchrboxwidth (int cmd)
- //cmd == 0 => set's 9 pixels character box width
- //cmd == 1 => set's 8 pixels character box width
- //cmd == 2 => if 9 pixel box width is selected, selects 8 pixels, and vice versa.
- {
- register unsigned char a0,a1;
- outportb(crt_EVGA_addr+4u,1u); //selects clocking mode register
- a0=inportb(crt_EVGA_addr+5u); //a0 <= VGA sequencer clocking mode register
- if (cmd==2)
- a0^=0x01; //XORS bit 0 of a0
- else if (cmd==1)
- a0|=0x01; //SETS bit 0 of a0
- else if (cmd==0)
- a0&=0xfe; //CLEARS bit 0 of a0
- outportb(crt_EVGA_addr+5u,a0);//VGA sequencer clocking mode register is loaded with a0
-
- a1=inportb(crt_EVGA_addr+0x0Cu);//a1 <= VGA miscellaneous output register
- a1&=0xf3; //clears bit 3 and 2.
- if (!(a0&0x01)) //if bit 0 of a1 is cleared (cmd==0)
- a1|=0x04; //sets bit 2 of a1, selecting the pixelclock frequency
- //for a character box 9 pixels wide.
- //otherwise (bit 2 reseted), selected frequency is for a
- //character box 8 pixels wide.
- outportb(crt_EVGA_addr+2u,a1); //VGA miscellaneous output register <= a1
- }
- //</FILE>
-
- //<FILE="textblnk.c">
- #define intm(intnum) asm int intnum
-
- void settextblink (int cmd) //if cmd==1 => set attribute bit 7 as enable blink
- //bit (default), otherwise it becomes background intensity bit
- {
- cmd%=(unsigned)256u;
- if ((unsigned)cmd>1)
- return;
- asm push ax;
- asm push bx;
- _BX=cmd;
- _AX=0x1003;
- intm (0x10);
- asm pop bx;
- asm pop ax;
- }
- //</FILE>
-
- //<FILE="changchr.c">
- #define intm(intnum) asm int intnum
- #define FP_SEG( fp )( (unsigned )( void _seg * )( void far * )( fp ))
- #define FP_OFF( fp )( (unsigned )( fp ))
-
- int changechar_height=16;
- int changechar_func=0x1100;
- int changechar_blk=0;
-
- void changechar (unsigned char *fmt, int ind, int qt)
- {
- if(changechar_func!=0x1100 && changechar_func!=0x1110)//protection against
- return; //wrong changechar_func values
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- asm push es;
- _BH=changechar_height;
- _BL=changechar_blk;
- _CX=qt;
- _DX=ind;
- _AX=changechar_func;
- asm push bp
- asm push ax
- _ES=FP_SEG(fmt);
- _BP=FP_OFF(fmt);
- asm pop ax;
- intm(0x10);
- asm pop bp;
- asm pop es;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- }
-
- void changecharg (unsigned char *fmt, int rows)
- {
- asm push ax;
- asm push bx;
- asm push cx;
- asm push dx;
- asm push es;
- _BL=0x00;
- _CX=changechar_height;
- _DL=rows;
- asm push bp
- _ES=FP_SEG(fmt);
- _BP=FP_OFF(fmt);
- _AX=0x1121;
- intm(0x10);
- asm pop bp;
- asm pop es;
- asm pop dx;
- asm pop cx;
- asm pop bx;
- asm pop ax;
- }
- //</FILE>
-
- //<FILE="videolib.dat">
- + crtvar + crtdtect + crt_init + vmode + crtmode &
- + crtpage + crt_gtxy + getxy + getcrtch + getcrtco &
- + b_printc + printcn + printc + changeco + printct &
- + printsn + prints + printxy + printx + printt &
- + printsj + printsjc + printsnf + printsf + printxyf &
- + printxf + printtf + printsjf + prntsjcf + fillscr &
- + barcolor + fillbar + fillbarw + fillbox + fillboxw &
- + crtframe + crtframw + mkline + crtwin + savvideo &
- + rstvideo + savevidw + rstvidw + savvidw2 + rstvidw2 &
- + savecrt + rstcrt + savecrtw + rstcrtw + savcrtw2 &
- + rstcrtw2 + cursorsh + crtpal + crtbord + crtdacr &
- + boxwidth + textblnk + changchr
- //</FILE>
-
- //<FILE="compile.bat">
- tcc -c -m%1 %2 %3 %4 %5 %6 %7 %8 %9 *.c
- tlib video%1 @videolib.dat
- del *.obj
- //</FILE>
-
- //<FILE="asmlibs.bat">
- call compile s %1 %2 %3 %4 %5 %6 %7 %8 %9
- call compile m %1 %2 %3 %4 %5 %6 %7 %8 %9
- call compile c %1 %2 %3 %4 %5 %6 %7 %8 %9
- call compile l %1 %2 %3 %4 %5 %6 %7 %8 %9
- call compile h %1 %2 %3 %4 %5 %6 %7 %8 %9
- @echo
- @echo If you wish to create libraries for 186 or 286 Protected Mode Instructions
- @echo use the lines below
- @echo tcc -c -1 [options] *.c
- @echo tlib video186 @videolib.dat
- @echo tcc -c -2 [options] *.c
- @echo tlib video286 @videolib.dat
- //</FILE>
-